package br.pucrio.inf.aaaong.models.domain.database.dao.basic;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;

public class ArtificialIdDAO {
	public enum Type {
		Adolescente;
	}
	
	private Connection connection;

	public ArtificialIdDAO(Connection connection) {
		this.connection = connection;
	}
	
	public int nextFor(Type type) {
		try {
			CallableStatement cs = connection.prepareCall("{? = call nextArtificialId(?)}");
			cs.registerOutParameter(1, Types.INTEGER);
			cs.setString(2, type.name());
			cs.execute();
			return cs.getInt(1);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("Next artificial id failed");
		}
	}
}